package com.yanqu.xiuxian.crosssystem.manger.elementalbonds.enums;

import com.yanqu.xiuxian.config.elementalbonds.ElementalBondsSceneConfig;
import com.yanqu.xiuxian.config.elementalbonds.enums.*;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.data.ElementalBondsGameData;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.data.ElementalBondsPlayerData;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.entity.ElementalBondsBlock;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.entity.ElementalBondsBlockEffect;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.entity.ElementalBondsOperateEffect;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.entity.ElementalBondsOperateShow;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.logic.ElementalBondsBlockLogic;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.logic.ElementalBondsEliminateLogic;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.logic.ElementalBondsFrameLogic;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.logic.ElementalBondsSceneLogic;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.result.ElementalBondsOperateResult;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.result.ElementalBondsOperateRoundResult;
import com.yanqu.xiuxian.crosssystem.manger.elementalbonds.result.ElementalBondsOperateStageResult;

import java.util.*;
import java.util.stream.Collectors;

public enum ElementalBondsSceneType {

    EMPTY(1, "空"),
    ZHAO_CAI_JIN_BAO(2, "招财进宝") {
        @Override
        public void refresh(ElementalBondsSceneConfig elementalBondsSceneConfig,
                            ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                            Random random) {
            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int addScore = paramList.get(0);
            int num = paramList.get(1);
            int color = paramList.get(2);

            List<List<ElementalBondsBlock>> blockList = elementalBondsGameData.getBlockList();

            // 可选方块
            List<ElementalBondsBlock> randomElementalBondsBlockList = new ArrayList<>();
            for (List<ElementalBondsBlock> elementalBondsBlockList : blockList) {
                for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockList) {
                    if (elementalBondsBlock.getColor() == color && elementalBondsBlock.getElementalBondsBlockType() == ElementalBondsBlockType.NORMAL) {
                        randomElementalBondsBlockList.add(elementalBondsBlock);
                    }
                }
            }

            // 随机替换
            List<ElementalBondsBlock> changeElementalBondsBlockList = new ArrayList<>();
            Collections.shuffle(randomElementalBondsBlockList, random);
            for (int i = 0; i < num && i < randomElementalBondsBlockList.size(); i++) {

                ElementalBondsBlock elementalBondsBlock = randomElementalBondsBlockList.get(i).clone();
                elementalBondsBlock.setElementalBondsBlockType(ElementalBondsBlockType.ZHAO_CAI_JIN_BAO);
                elementalBondsBlock.addElementalBondsBlockEffect(new ElementalBondsBlockEffect(ElementalBondsBlockEffectType.ADD_SCORE, addScore));
                blockList.get(elementalBondsBlock.getY()).set(elementalBondsBlock.getX(), elementalBondsBlock);

                changeElementalBondsBlockList.add(elementalBondsBlock);
            }

            // 技能效果
            if (!changeElementalBondsBlockList.isEmpty()) {
                elementalBondsOperateResult.addElementalBondsOperateEffect(new ElementalBondsOperateEffect(ElementalBondsEffectType.REPLACE_BLOCK, changeElementalBondsBlockList));
            }
        }
    }, // 橙色额外加分|每次刷新数量|关联颜色|0
    LUO_GU_XUAN_TIAN(3, "锣鼓喧天") {
        @Override
        public void init(ElementalBondsSceneConfig elementalBondsSceneConfig,
                         ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                         Random random) {
            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int initScore = paramList.get(0);

            // 中心位置
            List<List<ElementalBondsBlock>> blockList = elementalBondsGameData.getBlockList();
            List<ElementalBondsBlock> elementalBondsBlockList = blockList.get(blockList.size() / 2);
            ElementalBondsBlock elementalBondsBlock = elementalBondsBlockList.get(elementalBondsBlockList.size() / 2);

            // 生成框
            ElementalBondsBlockEffect elementalBondsBlockEffect = new ElementalBondsBlockEffect(ElementalBondsBlockEffectType.LUO_GU_XUAN_TIAN, initScore);
            ElementalBondsBlock frame = ElementalBondsBlock.createFrame(elementalBondsBlock.getX(), elementalBondsBlock.getY(), ElementalBondsBlockType.LUO_GU_XUAN_TIAN);
            frame.addElementalBondsBlockEffect(elementalBondsBlockEffect);
            elementalBondsGameData.addFrame(frame);
        }

        @Override
        public void operateEnd(ElementalBondsSceneConfig elementalBondsSceneConfig,
                               ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                               Random random, boolean checkCanChange) {
            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int initScore = paramList.get(0);
            int addScore = paramList.get(1);

            Map<Integer, Map<Integer, ElementalBondsBlock>> frameMap = elementalBondsGameData.getFrameMap();
            List<ElementalBondsBlock> changeElementalBondsBlockList = new ArrayList<>();

            // 未消除锣鼓加分
            if (elementalBondsOperateResult.getElementalBondsOperateType() == ElementalBondsOperateType.MOVE) {
                for (Map<Integer, ElementalBondsBlock> map : frameMap.values()) {
                    for (ElementalBondsBlock frame : map.values()) {
                        if (frame.getElementalBondsBlockType() == ElementalBondsBlockType.LUO_GU_XUAN_TIAN) {
                            for (ElementalBondsBlockEffect elementalBondsBlockEffect : frame.getElementalBondsBlockEffectList()) {
                                if (elementalBondsBlockEffect.getEffectType() == ElementalBondsBlockEffectType.LUO_GU_XUAN_TIAN) {
                                    elementalBondsBlockEffect.addEffectValue(addScore);
                                }
                            }
                            changeElementalBondsBlockList.add(frame);
                        }
                    }
                }
            }

            // 已消除锣鼓重置
            for (Map<Integer, ElementalBondsBlock> map : frameMap.values()) {
                for (ElementalBondsBlock frame : map.values()) {
                    if (frame.getElementalBondsBlockType() == ElementalBondsBlockType.LUO_GU_XUAN_TIAN_DEL) {

                        // 移除旧的
                        map.remove(frame.getX());

                        // 添加新的
                        ElementalBondsBlockEffect elementalBondsBlockEffect = new ElementalBondsBlockEffect(ElementalBondsBlockEffectType.LUO_GU_XUAN_TIAN, initScore);
                        ElementalBondsBlock tmpFrame = ElementalBondsBlock.createFrame(frame.getX(), frame.getY(), ElementalBondsBlockType.LUO_GU_XUAN_TIAN);
                        tmpFrame.addElementalBondsBlockEffect(elementalBondsBlockEffect);
                        elementalBondsGameData.addFrame(tmpFrame);

                        changeElementalBondsBlockList.add(frame);
                    }
                }
            }

            if (!changeElementalBondsBlockList.isEmpty()) {
                elementalBondsOperateResult.addElementalBondsOperateEffect(new ElementalBondsOperateEffect(ElementalBondsEffectType.UPDATE_BLOCK, changeElementalBondsBlockList));
            }
        }
    }, // 初始分数|每步加分|0|0
    HUO_YAO_KUANG_HUAN(4, "火药狂欢") {
        @Override
        public void init(ElementalBondsSceneConfig elementalBondsSceneConfig,
                         ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                         Random random) {
            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int initNum = paramList.get(0);

            // 可选格子
            List<ElementalBondsBlock> randomElementalBondsBlockList = new ArrayList<>();
            List<List<ElementalBondsBlock>> blockList = elementalBondsGameData.getBlockList();
            for (List<ElementalBondsBlock> elementalBondsBlockList : blockList) {
                for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockList) {
                    if (elementalBondsBlock.getElementalBondsBlockType().getBigType() == ElementalBondsBlockBigType.NORMAL) {
                        randomElementalBondsBlockList.add(elementalBondsBlock);
                    }
                }
            }

            // 实际替换
            Collections.shuffle(randomElementalBondsBlockList, random);
            for (int i = 0; i < initNum && i < randomElementalBondsBlockList.size(); i++) {
                ElementalBondsBlock elementalBondsBlock = randomElementalBondsBlockList.get(i);
                elementalBondsBlock.setElementalBondsBlockType(ElementalBondsBlockType.HUO_YAO_KUANG_HUAN);
            }
        }

        @Override
        public void replaceDropBlock(ElementalBondsSceneConfig elementalBondsSceneConfig,
                                     ElementalBondsGameData elementalBondsGameData, List<ElementalBondsBlock> elementalBondsBlockList,
                                     Random random) {
            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int boardMaxNum = paramList.get(1);
            int ratio = paramList.get(2);
            int turnMaxNum = paramList.get(3);

            // 回合数量
            int scene04Count = elementalBondsGameData.getScene04Count();
            if (scene04Count >= turnMaxNum) {
                return;
            }

            // 已有数量
            int haveNum = 0;
            for (List<ElementalBondsBlock> elementalBondsBlocks : elementalBondsGameData.getBlockList()) {
                for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlocks) {
                    if (elementalBondsBlock != null) {
                        if (elementalBondsBlock.getElementalBondsBlockType() == ElementalBondsBlockType.HUO_YAO_KUANG_HUAN) {
                            haveNum++;
                        }
                    }
                }
            }
            if (haveNum >= boardMaxNum) {
                return;
            }

            // 随机替换
            List<ElementalBondsBlock> randomElementalBondsBlockList = new ArrayList<>(elementalBondsBlockList);
            Collections.shuffle(randomElementalBondsBlockList);
            int limitNum = Math.min(boardMaxNum - haveNum, turnMaxNum - scene04Count);
            int realNum = 0;
            for (ElementalBondsBlock elementalBondsBlock : randomElementalBondsBlockList) {
                if (realNum >= limitNum) {
                    break;
                }
                if (random.nextInt(1000) < ratio) {
                    elementalBondsBlock.setElementalBondsBlockType(ElementalBondsBlockType.HUO_YAO_KUANG_HUAN);
                    realNum++;
                }
            }
            // 修改数据
            elementalBondsGameData.setScene04Count(scene04Count + realNum);
        }
    }, // 初始个数|稳定个数|掉落概率千分比|数量上限
    JIE_JIE_GAO(5, "节节高") {
        @Override
        public void init(ElementalBondsSceneConfig elementalBondsSceneConfig,
                         ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                         Random random) {
            this.operateEnd(elementalBondsSceneConfig, elementalBondsGameData, elementalBondsOperateResult, random, false);
        }

        @Override
        public void operateEnd(ElementalBondsSceneConfig elementalBondsSceneConfig,
                               ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                               Random random, boolean checkCanChange) {
            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int baseScore = paramList.get(0);
            int addScore = paramList.get(1);
            int boardMaxNum = paramList.get(2);
            int color = paramList.get(3);

            List<List<ElementalBondsBlock>> blockList = elementalBondsGameData.getBlockList();

            // 可选方块
            int haveNum = 0;
            List<ElementalBondsBlock> rendomElementalBondsBlockList = new ArrayList<>();
            for (List<ElementalBondsBlock> elementalBondsBlockList : blockList) {
                for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockList) {
                    if (elementalBondsBlock.getElementalBondsBlockType() == ElementalBondsBlockType.JIE_JIE_GAO) {
                        haveNum++;
                    }
                    if (elementalBondsBlock.getColor() == color && elementalBondsBlock.getElementalBondsBlockType() == ElementalBondsBlockType.NORMAL) {
                        rendomElementalBondsBlockList.add(elementalBondsBlock);
                    }
                }
            }
            if (haveNum >= boardMaxNum) {
                return;
            }

            // 随机替换
            List<ElementalBondsBlock> chhangeElementalBondsBlockList = new ArrayList<>();
            Collections.shuffle(rendomElementalBondsBlockList, random);
            for (int i = 0; i < boardMaxNum - haveNum && i < rendomElementalBondsBlockList.size(); i++) {

                ElementalBondsBlockEffect elementalBondsBlockEffect = new ElementalBondsBlockEffect(ElementalBondsBlockEffectType.ADD_SCORE);
                elementalBondsBlockEffect.setEffectValue(baseScore + elementalBondsGameData.getScene05Count() * addScore);

                ElementalBondsBlock clone = rendomElementalBondsBlockList.get(i).clone();
                clone.setElementalBondsBlockType(ElementalBondsBlockType.JIE_JIE_GAO);
                clone.getElementalBondsBlockEffectList().add(elementalBondsBlockEffect);
                blockList.get(clone.getY()).set(clone.getX(), clone);

                elementalBondsGameData.setScene05Count(elementalBondsGameData.getScene05Count() + 1);
                chhangeElementalBondsBlockList.add(clone);
            }

            // 添加效果
            if (!chhangeElementalBondsBlockList.isEmpty()) {
                elementalBondsOperateResult.addElementalBondsOperateEffect(new ElementalBondsOperateEffect(ElementalBondsEffectType.REPLACE_BLOCK, chhangeElementalBondsBlockList));
            }
        }
    }, // 首个水晶花加分|递增分|稳定数量|关联颜色
    GUI_KE_ZHAN_BU(6, "龟壳占卜") {
        @Override
        public void refresh(ElementalBondsSceneConfig elementalBondsSceneConfig,
                            ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                            Random random) {
            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int num = paramList.get(0);
            int color = paramList.get(1);

            List<List<ElementalBondsBlock>> blockList = elementalBondsGameData.getBlockList();

            // 可选方块
            List<ElementalBondsBlock> randomElementalBondsBlockList = new ArrayList<>();
            for (List<ElementalBondsBlock> elementalBondsBlockList : blockList) {
                for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockList) {
                    if (elementalBondsBlock.getColor() == color && elementalBondsBlock.getElementalBondsBlockType() == ElementalBondsBlockType.NORMAL) {
                        randomElementalBondsBlockList.add(elementalBondsBlock);
                    }
                }
            }

            // 随机替换
            List<ElementalBondsBlock> changeElementalBondsBlockList = new ArrayList<>();
            Collections.shuffle(randomElementalBondsBlockList, random);
            for (int i = 0; i < num && i < randomElementalBondsBlockList.size(); i++) {

                ElementalBondsBlock elementalBondsBlock = randomElementalBondsBlockList.get(i).clone();
                elementalBondsBlock.setElementalBondsBlockType(ElementalBondsBlockType.GUI_KE_ZHAN_BU);
                blockList.get(elementalBondsBlock.getY()).set(elementalBondsBlock.getX(), elementalBondsBlock);

                changeElementalBondsBlockList.add(elementalBondsBlock);
            }

            // 技能效果
            if (!changeElementalBondsBlockList.isEmpty()) {
                elementalBondsOperateResult.addElementalBondsOperateEffect(new ElementalBondsOperateEffect(ElementalBondsEffectType.REPLACE_BLOCK, changeElementalBondsBlockList));
            }
        }
    }, // 每次刷新数量|关联颜色|随机消除基础元素数量|0
    BAI_BAO_XIANG(7, "百宝箱") {
        @Override
        public void init(ElementalBondsSceneConfig elementalBondsSceneConfig,
                         ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                         Random random) {
            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int boardMaxNum = paramList.get(1);

            // 可选格子
            List<List<ElementalBondsBlock>> blockList = elementalBondsGameData.getBlockList();
            List<ElementalBondsBlock> elementalBondsBlockList = blockList.get(blockList.size() - 1).stream()
                    .filter(elementalBondsBlock -> elementalBondsBlock.getElementalBondsBlockType().getBigType() == ElementalBondsBlockBigType.NORMAL)
                    .collect(Collectors.toList());

            // 随机替换
            Collections.shuffle(elementalBondsBlockList, random);
            for (int i = 0; i < boardMaxNum; i++) {
                ElementalBondsBlock elementalBondsBlock = elementalBondsBlockList.get(i);
                elementalBondsBlock.setElementalBondsBlockType(ElementalBondsBlockType.BAI_BAO_XIANG);
                elementalBondsBlock.setColor(ElementalBondsColorType.NONE.getType());
            }
        }

        @Override
        public void operateEnd(ElementalBondsSceneConfig elementalBondsSceneConfig,
                               ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                               Random random, boolean checkCanChange) {
            // 暂存宝箱打开
            if (!elementalBondsGameData.getScene07StageBoxList().isEmpty()) {
                elementalBondsOperateResult.addElementalBondsOperateEffect(new ElementalBondsOperateEffect(ElementalBondsEffectType.OPEN_STAGE_BOX, elementalBondsGameData.getScene07StageBoxList()));
                // 清空
                elementalBondsGameData.setScene07StageBoxList(new ArrayList<>());
            }
        }

        @Override
        public void replaceDropBlock(ElementalBondsSceneConfig elementalBondsSceneConfig,
                                     ElementalBondsGameData elementalBondsGameData, List<ElementalBondsBlock> elementalBondsBlockList,
                                     Random random) {
            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int boardMaxNum = paramList.get(1);
            int ratio = paramList.get(2);
            int turnMaxNum = paramList.get(3);

            // 回合数量
            int scene07Count = elementalBondsGameData.getScene07Count();
            if (scene07Count >= turnMaxNum) {
                return;
            }

            // 已有数量
            int haveNum = 0;
            List<List<ElementalBondsBlock>> blockList = elementalBondsGameData.getBlockList();
            for (List<ElementalBondsBlock> elementalBondsBlocks : blockList) {
                for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlocks) {
                    if (elementalBondsBlock != null) {
                        if (elementalBondsBlock.getElementalBondsBlockType() == ElementalBondsBlockType.BAI_BAO_XIANG) {
                            haveNum++;
                        }
                    }
                }
            }
            if (haveNum >= boardMaxNum) {
                return;
            }

            // 可随机方块
            List<ElementalBondsBlock> randomElementalBondsBlockList = new ArrayList<>();
            int topY = blockList.size() - 1;
            for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockList) {
                if (elementalBondsBlock.getY() == topY) {
                    randomElementalBondsBlockList.add(elementalBondsBlock);
                }
            }

            // 随机替换
            Collections.shuffle(randomElementalBondsBlockList);
            int limitNum = Math.min(boardMaxNum - haveNum, turnMaxNum - scene07Count);
            int realNum = 0;
            for (ElementalBondsBlock elementalBondsBlock : randomElementalBondsBlockList) {
                if (realNum >= limitNum) {
                    break;
                }
                if (random.nextInt(1000) < ratio) {
                    elementalBondsBlock.setElementalBondsBlockType(ElementalBondsBlockType.BAI_BAO_XIANG);
                    elementalBondsBlock.setColor(ElementalBondsColorType.NONE.getType());
                    realNum++;
                }
            }
            // 修改数据
            elementalBondsGameData.setScene04Count(scene07Count + realNum);
        }

        @Override
        public void eliminateEnd(ElementalBondsSceneConfig elementalBondsSceneConfig,
                                 ElementalBondsGameData elementalBondsGameData, ElementalBondsPlayerData elementalBondsPlayerData,
                                 ElementalBondsOperateResult elementalBondsOperateResult,
                                 Random random, int roomRound, int turnPlayer) {
            for (int times = 0; times < 50; times++) {
                List<ElementalBondsBlock> changeElementalBondsBlockList = new ArrayList<>();
                List<List<ElementalBondsBlock>> blockList = elementalBondsGameData.getBlockList();
                List<ElementalBondsBlock> elementalBondsBlockList = blockList.get(0);
                for (int i = 0; i < elementalBondsBlockList.size(); i++) {
                    ElementalBondsBlock elementalBondsBlock = elementalBondsBlockList.get(i);
                    if (elementalBondsBlock.getElementalBondsBlockType() == ElementalBondsBlockType.BAI_BAO_XIANG) {
                        elementalBondsBlockList.set(i, null);
                        changeElementalBondsBlockList.add(elementalBondsBlock);
                    }
                }
                if (changeElementalBondsBlockList.isEmpty()) {
                    break;
                }

                // 设置加蓝
                int addMp = elementalBondsSceneConfig.getParamList().get(0);
                for (ElementalBondsBlock elementalBondsBlock : changeElementalBondsBlockList) {
                    elementalBondsBlock.setSp(addMp);
                    elementalBondsOperateResult.addScene07AddMp(addMp);
                }

                // 加效果
                ElementalBondsEffectType elementalBondsEffectType = ElementalBondsEffectType.OPEN_BOX;
                if (elementalBondsOperateResult.getElementalBondsOperateType() == ElementalBondsOperateType.USE_CARD) {
                    elementalBondsGameData.getScene07StageBoxList().addAll(changeElementalBondsBlockList);
                    elementalBondsEffectType = ElementalBondsEffectType.STAGE_BOX;
                }
                elementalBondsOperateResult.addElementalBondsOperateEffect(new ElementalBondsOperateEffect(elementalBondsEffectType, changeElementalBondsBlockList));

                // 掉落方块
                ElementalBondsBlockLogic.drop(blockList, elementalBondsGameData, random, -1, roomRound, turnPlayer);
                elementalBondsOperateResult.addElementalBondsOperateRoundResult(new ElementalBondsOperateRoundResult(elementalBondsGameData.clone()));

                // 继续消除
                ElementalBondsEliminateLogic.eliminate(elementalBondsGameData, elementalBondsPlayerData,
                        null, new HashSet<>(), elementalBondsOperateResult, random, -1, roomRound, turnPlayer);
            }
        }
    }, // 获得技能进度|稳定数量|掉落概率千分比|掉落上限
    HONG_YOU_QING_HUA(8, "红釉青花") {
        @Override
        public void refresh(ElementalBondsSceneConfig elementalBondsSceneConfig,
                            ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                            Random random) {
            int color = elementalBondsOperateResult.getTurn() == 1 ? ElementalBondsColorType.RED.getType() : ElementalBondsColorType.BLUE.getType();
            List<List<ElementalBondsBlock>> blockList = elementalBondsGameData.getBlockList();
            for (List<ElementalBondsBlock> elementalBondsBlockList : blockList) {
                for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockList) {
                    if (elementalBondsBlock.getElementalBondsBlockType() == ElementalBondsBlockType.HONG_YOU_QING_HUA) {
                        elementalBondsBlock.setColor(color);
                    }
                }
            }
        }

        @Override
        public void init(ElementalBondsSceneConfig elementalBondsSceneConfig,
                         ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                         Random random) {
            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int initNum = paramList.get(1);

            // 可选方块
            List<ElementalBondsBlock> redElementalBondsBlockList = new ArrayList<>();
            List<ElementalBondsBlock> blueElementalBondsBlockList = new ArrayList<>();
            List<List<ElementalBondsBlock>> blockList = elementalBondsGameData.getBlockList();
            for (List<ElementalBondsBlock> elementalBondsBlockList : blockList) {
                for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockList) {
                    if (elementalBondsBlock.getElementalBondsBlockType().getBigType() == ElementalBondsBlockBigType.NORMAL) {
                        if (elementalBondsBlock.getColor() == ElementalBondsColorType.RED.getType()) {
                            redElementalBondsBlockList.add(elementalBondsBlock);
                        } else if (elementalBondsBlock.getColor() == ElementalBondsColorType.BLUE.getType()) {
                            blueElementalBondsBlockList.add(elementalBondsBlock);
                        }
                    }
                }
            }

            // 随机替换
            Collections.shuffle(redElementalBondsBlockList, random);
            Collections.shuffle(blueElementalBondsBlockList, random);
            int totalNum = initNum * 2;
            int blueIndex = 0;
            int redIndex = 0;
            List<ElementalBondsBlock> changeElementalBondsBlockList = new ArrayList<>();
            while (changeElementalBondsBlockList.size() < totalNum
                    && (blueIndex < blueElementalBondsBlockList.size() || redIndex < redElementalBondsBlockList.size())) { // 循环蓝色替换一个、红色替换一个，直到数量满足要求

                changeElementalBondsBlockList.forEach(elementalBondsBlock -> elementalBondsBlock.setColor(ElementalBondsColorType.RED.getType()));
                while (changeElementalBondsBlockList.size() < totalNum && blueIndex < blueElementalBondsBlockList.size()) {
                    ElementalBondsBlock elementalBondsBlock = blueElementalBondsBlockList.get(blueIndex++);
                    elementalBondsBlock.setColor(ElementalBondsColorType.RED.getType());
                    if (ElementalBondsEliminateLogic.canSameColorEliminate(elementalBondsGameData.getBlockList(), elementalBondsBlock)) {
                        elementalBondsBlock.setColor(ElementalBondsColorType.BLUE.getType());
                    } else {
                        elementalBondsBlock.setElementalBondsBlockType(ElementalBondsBlockType.HONG_YOU_QING_HUA);
                        changeElementalBondsBlockList.add(elementalBondsBlock);
                        break;
                    }
                }

                changeElementalBondsBlockList.forEach(elementalBondsBlock -> elementalBondsBlock.setColor(ElementalBondsColorType.BLUE.getType()));
                while (changeElementalBondsBlockList.size() < totalNum && redIndex < redElementalBondsBlockList.size()) {
                    ElementalBondsBlock elementalBondsBlock = redElementalBondsBlockList.get(redIndex++);
                    elementalBondsBlock.setColor(ElementalBondsColorType.BLUE.getType());
                    if (ElementalBondsEliminateLogic.canSameColorEliminate(elementalBondsGameData.getBlockList(), elementalBondsBlock)) {
                        elementalBondsBlock.setColor(ElementalBondsColorType.RED.getType());
                    } else {
                        elementalBondsBlock.setElementalBondsBlockType(ElementalBondsBlockType.HONG_YOU_QING_HUA);
                        changeElementalBondsBlockList.add(elementalBondsBlock);
                        break;
                    }
                }
            }
            changeElementalBondsBlockList.forEach(elementalBondsBlock -> elementalBondsBlock.setColor(ElementalBondsColorType.NONE.getType()));
        }

        @Override
        public void replaceDropBlock(ElementalBondsSceneConfig elementalBondsSceneConfig,
                                     ElementalBondsGameData elementalBondsGameData, List<ElementalBondsBlock> elementalBondsBlockList,
                                     Random random) {
            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int boardMaxNum = paramList.get(1);
            int ratio = paramList.get(2);
            int turnMaxNum = paramList.get(3);

            // 回合数量
            int scene08Count = elementalBondsGameData.getScene08Count();
            if (scene08Count >= turnMaxNum) {
                return;
            }

            // 已有数量
            int haveNum = 0;
            for (List<ElementalBondsBlock> elementalBondsBlocks : elementalBondsGameData.getBlockList()) {
                for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlocks) {
                    if (elementalBondsBlock != null) {
                        if (elementalBondsBlock.getElementalBondsBlockType() == ElementalBondsBlockType.HONG_YOU_QING_HUA) {
                            haveNum++;
                        }
                    }
                }
            }
            if (haveNum >= boardMaxNum) {
                return;
            }

            // 拿格子
            List<ElementalBondsBlock> randomElementalBondsBlockList = new ArrayList<>();
            for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockList) {
                if (elementalBondsBlock.getColor() == ElementalBondsColorType.RED.getType() || elementalBondsBlock.getColor() == ElementalBondsColorType.BLUE.getType()) {
                    randomElementalBondsBlockList.add(elementalBondsBlock);
                }
            }

            // 随机替换
            Collections.shuffle(randomElementalBondsBlockList);
            int limitNum = Math.min(boardMaxNum - haveNum, turnMaxNum - scene08Count);
            int realNum = 0;
            for (ElementalBondsBlock elementalBondsBlock : randomElementalBondsBlockList) {
                if (realNum >= limitNum) {
                    break;
                }
                if (random.nextInt(1000) < ratio) {
                    elementalBondsBlock.setElementalBondsBlockType(ElementalBondsBlockType.HONG_YOU_QING_HUA);
                    realNum++;
                }
            }

            // 修改数据
            elementalBondsGameData.setScene04Count(scene08Count + realNum);
        }
    }, // 初始数量|稳定数量|掉落概率千分比|掉落上限
    DIAN_SHAN_LEI_MING(9, "电闪雷鸣") {
        @Override
        public void refresh(ElementalBondsSceneConfig elementalBondsSceneConfig,
                            ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                            Random random) {
            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int boardMaxNum = paramList.get(1);

            // 已有数量
            int haveNum = 0;
            for (Map<Integer, ElementalBondsBlock> elementalBondsBlockMap : elementalBondsGameData.getFrameMap().values()) {
                for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockMap.values()) {
                    if (elementalBondsBlock.getElementalBondsBlockType() == ElementalBondsBlockType.DIAN_SHAN_LEI_MING) {
                        haveNum++;
                    }
                }
            }
            if (haveNum >= boardMaxNum) {
                return;
            }

            // 随机生成框
            List<ElementalBondsBlock> changeElementalBondsBlockList = new ArrayList<>();
            List<ElementalBondsBlock> elementalBondsBlockList = ElementalBondsFrameLogic.randomFramePos(elementalBondsGameData, random, boardMaxNum - haveNum);
            for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockList) {
                ElementalBondsBlock frame = ElementalBondsBlock.createFrame(elementalBondsBlock.getX(), elementalBondsBlock.getY(), ElementalBondsBlockType.DIAN_SHAN_LEI_MING);
                elementalBondsGameData.addFrame(frame);
                changeElementalBondsBlockList.add(frame);
            }

            // 技能效果
            if (!changeElementalBondsBlockList.isEmpty()) {
                elementalBondsOperateResult.addElementalBondsOperateEffect(new ElementalBondsOperateEffect(ElementalBondsEffectType.UPDATE_BLOCK, changeElementalBondsBlockList));
            }
        }

        @Override
        public void init(ElementalBondsSceneConfig elementalBondsSceneConfig,
                         ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                         Random random) {
            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int initNum = paramList.get(0);

            List<ElementalBondsBlock> elementalBondsBlockList = ElementalBondsFrameLogic.randomFramePos(elementalBondsGameData, random, initNum);
            for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockList) {
                ElementalBondsBlock frame = ElementalBondsBlock.createFrame(elementalBondsBlock.getX(), elementalBondsBlock.getY(), ElementalBondsBlockType.DIAN_SHAN_LEI_MING);
                elementalBondsGameData.addFrame(frame);
            }
        }

        @Override
        public void afterSameColorEliminate(ElementalBondsSceneConfig elementalBondsSceneConfig,
                                            ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateStageResult elementalBondsOperateStageResult,
                                            Set<ElementalBondsBlock> elementalBondsBlockSet, ElementalBondsOperateType elementalBondsOperateType) {
            // 卡片不能消除框
            if (elementalBondsOperateType != ElementalBondsOperateType.MOVE && elementalBondsOperateType != ElementalBondsOperateType.USE_SKILL) {
                return;
            }

            List<List<ElementalBondsBlock>> blockList = elementalBondsGameData.getBlockList();
            Map<Integer, Map<Integer, ElementalBondsBlock>> frameMap = elementalBondsGameData.getFrameMap();

            List<ElementalBondsBlock> changeElementalBondsBlockList = new ArrayList<>();
            for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockSet) {
                Map<Integer, ElementalBondsBlock> elementalBondsBlockMap = frameMap.get(elementalBondsBlock.getY());
                if (elementalBondsBlockMap != null) {
                    ElementalBondsBlock frame = elementalBondsBlockMap.get(elementalBondsBlock.getX());
                    if (frame != null && frame.getElementalBondsBlockType() == ElementalBondsBlockType.DIAN_SHAN_LEI_MING) {
                        if (ElementalBondsEliminateLogic.canSameColorEliminate(blockList, elementalBondsBlock)) {
                            // 消除框
                            elementalBondsBlockMap.remove(frame.getX());
                            changeElementalBondsBlockList.add(frame);
                            // 设置加步数效果
                            elementalBondsOperateStageResult.getAddStepBlockList().add(frame);
                        }
                    }
                }
            }

            elementalBondsBlockSet.addAll(changeElementalBondsBlockList);
        }
    }, // 初始数量|稳定数量|增加步数|0
    YI_BEN_WAN_LI(10, "一本万利") {
        @Override
        public void refresh(ElementalBondsSceneConfig elementalBondsSceneConfig,
                            ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                            Random random) {
            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int multi = paramList.get(0);
            int boardMaxNum = paramList.get(1);

            // 已有数量
            int haveNum = 0;
            for (Map<Integer, ElementalBondsBlock> elementalBondsBlockMap : elementalBondsGameData.getFrameMap().values()) {
                for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockMap.values()) {
                    if (elementalBondsBlock.getElementalBondsBlockType() == ElementalBondsBlockType.YI_BEN_WAN_LI) {
                        haveNum++;
                    }
                }
            }
            if (haveNum >= boardMaxNum) {
                return;
            }

            // 随机生成框
            List<ElementalBondsBlock> changeElementalBondsBlockList = new ArrayList<>();
            List<ElementalBondsBlock> elementalBondsBlockList = ElementalBondsFrameLogic.randomFramePos(elementalBondsGameData, random, boardMaxNum - haveNum);
            for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockList) {
                ElementalBondsBlock frame = ElementalBondsBlock.createFrame(elementalBondsBlock.getX(), elementalBondsBlock.getY(), ElementalBondsBlockType.YI_BEN_WAN_LI);
                frame.addElementalBondsBlockEffect(new ElementalBondsBlockEffect(ElementalBondsBlockEffectType.YI_BEN_WAN_LI, multi));
                elementalBondsGameData.addFrame(frame);
                changeElementalBondsBlockList.add(frame);
            }

            // 技能效果
            if (!changeElementalBondsBlockList.isEmpty()) {
                elementalBondsOperateResult.addElementalBondsOperateEffect(new ElementalBondsOperateEffect(ElementalBondsEffectType.UPDATE_BLOCK, changeElementalBondsBlockList));
            }
        }

        @Override
        public void afterSameColorEliminate(ElementalBondsSceneConfig elementalBondsSceneConfig,
                                            ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateStageResult elementalBondsOperateStageResult,
                                            Set<ElementalBondsBlock> elementalBondsBlockSet, ElementalBondsOperateType elementalBondsOperateType) {
            // 卡片不能消除框
            if (elementalBondsOperateType != ElementalBondsOperateType.MOVE && elementalBondsOperateType != ElementalBondsOperateType.USE_SKILL) {
                return;
            }

            int multi = elementalBondsSceneConfig.getParamList().get(0);

            // 拿格子
            List<ElementalBondsBlock> frameElementalBondsBlockList = new ArrayList<>();
            List<List<ElementalBondsBlock>> blockList = elementalBondsGameData.getBlockList();
            Map<Integer, Map<Integer, ElementalBondsBlock>> frameMap = elementalBondsGameData.getFrameMap();
            for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockSet) {
                if (frameMap.containsKey(elementalBondsBlock.getY()) && frameMap.get(elementalBondsBlock.getY()).containsKey(elementalBondsBlock.getX())) {
                    if (ElementalBondsEliminateLogic.canSameColorEliminate(blockList, elementalBondsBlock)) {
                        frameElementalBondsBlockList.add(frameMap.get(elementalBondsBlock.getY()).get(elementalBondsBlock.getX()));
                    }
                }
            }
            if (frameElementalBondsBlockList.isEmpty()) {
                return;
            }

            // 找消除组处理
            Map<Integer, List<List<ElementalBondsBlock>>> listMap = ElementalBondsEliminateLogic.groupEliminateSet(elementalBondsBlockSet);
            for (ElementalBondsBlock frame : frameElementalBondsBlockList) {
                for (List<List<ElementalBondsBlock>> listList : listMap.values()) {
                    for (List<ElementalBondsBlock> elementalBondsBlockList : listList) {
                        boolean anyMatch = elementalBondsBlockList.stream().anyMatch(elementalBondsBlock -> elementalBondsBlock.getX() == frame.getX()
                                && elementalBondsBlock.getY() == frame.getY());
                        // 找到框所在消除组了
                        if (anyMatch) {
                            // 消除框
                            frameMap.get(frame.getY()).remove(frame.getX());
                            elementalBondsBlockSet.add(frame);
                            // 同色消除的格子加效果    （可同色消除 + 只能有一个一本万利）
                            for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockList) {
                                if (ElementalBondsEliminateLogic.canSameColorEliminate(blockList, elementalBondsBlock)) {
                                    if (elementalBondsBlock.getElementalBondsBlockEffectList().stream()
                                            .noneMatch(elementalBondsBlockEffect ->
                                                    elementalBondsBlockEffect.getEffectType() == ElementalBondsBlockEffectType.MULTI_SCORE_HIDE)) {
                                        ElementalBondsBlockEffect elementalBondsBlockEffect = new ElementalBondsBlockEffect(ElementalBondsBlockEffectType.MULTI_SCORE_HIDE, multi);
                                        elementalBondsBlock.addElementalBondsBlockEffect(elementalBondsBlockEffect);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }, // 增加倍数|稳定数量|0|0
    DUN_HUANG_FEI_TIAN(11, "敦煌飞天") {
        @Override
        public void refresh(ElementalBondsSceneConfig elementalBondsSceneConfig,
                            ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                            Random random) {
            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int boardMaxNum = paramList.get(0);

            // 已有数量
            int haveNum = 0;
            for (Map<Integer, ElementalBondsBlock> elementalBondsBlockMap : elementalBondsGameData.getFrameMap().values()) {
                for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockMap.values()) {
                    if (elementalBondsBlock.getElementalBondsBlockType() == ElementalBondsBlockType.DUN_HUANG_FEI_TIAN) {
                        haveNum++;
                    }
                }
            }
            if (haveNum >= boardMaxNum) {
                return;
            }

            // 随机生成框
            List<ElementalBondsBlock> changeElementalBondsBlockList = new ArrayList<>();
            List<ElementalBondsBlock> elementalBondsBlockList = ElementalBondsFrameLogic.randomFramePos(elementalBondsGameData, random, boardMaxNum - haveNum);
            for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockList) {
                ElementalBondsBlock frame = ElementalBondsBlock.createFrame(elementalBondsBlock.getX(), elementalBondsBlock.getY(), ElementalBondsBlockType.DUN_HUANG_FEI_TIAN);
                elementalBondsGameData.addFrame(frame);
                changeElementalBondsBlockList.add(frame);
            }

            // 技能效果
            if (!changeElementalBondsBlockList.isEmpty()) {
                elementalBondsOperateResult.addElementalBondsOperateEffect(new ElementalBondsOperateEffect(ElementalBondsEffectType.UPDATE_BLOCK, changeElementalBondsBlockList));
            }
        }
    }, // 稳定刷新数量|0|0|0
    WU_CAI_BIN_FEN(12, "五彩缤纷") {
        @Override
        public void init(ElementalBondsSceneConfig elementalBondsSceneConfig,
                         ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                         Random random) {
            this.operateEnd(elementalBondsSceneConfig, elementalBondsGameData, elementalBondsOperateResult, random, false);
        }

        @Override
        public void operateEnd(ElementalBondsSceneConfig elementalBondsSceneConfig,
                               ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                               Random random, boolean checkCanChange) {
            if (checkCanChange && canChange(elementalBondsOperateResult)) {
                return;
            }

            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int minAddScore = paramList.get(0);
            int maxAddScore = paramList.get(1);

            List<List<ElementalBondsBlock>> blockList = elementalBondsGameData.getBlockList();

            // 选择颜色
            int scene12Color = elementalBondsGameData.getScene12Color();
            if (scene12Color == 0) {
                scene12Color = random.nextInt(6 - 2) + 3; // 共6色，排除红蓝2色
            }
            scene12Color = (scene12Color - 3 + 1) % 4 + 3; // 切换到下一种颜色

            // 随机分数
            int score = random.nextInt(maxAddScore - minAddScore) + minAddScore;

            // 记录数据
            elementalBondsGameData.setScene12Color(scene12Color);
            elementalBondsGameData.setScene12Score(score);

            // 效果变化
            Set<ElementalBondsBlock> changeElementalBondsBlockSet = new HashSet<>();
            for (List<ElementalBondsBlock> elementalBondsBlockList : blockList) {
                for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockList) {
                    if (ElementalBondsSceneLogic.scene_12_checkEffectChange(elementalBondsBlock, elementalBondsGameData)) {
                        changeElementalBondsBlockSet.add(elementalBondsBlock);
                    }
                }
            }

            // 添加效果
            if (!changeElementalBondsBlockSet.isEmpty()) {
                elementalBondsOperateResult.addElementalBondsOperateEffect(new ElementalBondsOperateEffect(ElementalBondsEffectType.UPDATE_BLOCK, new ArrayList<>(changeElementalBondsBlockSet)));
            }
        }

        private boolean canChange(ElementalBondsOperateResult elementalBondsOperateResult) {
            for (ElementalBondsOperateShow elementalBondsOperateShow : elementalBondsOperateResult.getElementalBondsOperateShowList()) {
                for (ElementalBondsOperateRoundResult elementalBondsOperateRoundResult : elementalBondsOperateShow.getElementalBondsOperateRoundResultList()) {
                    for (ElementalBondsOperateStageResult elementalBondsOperateStageResult : elementalBondsOperateRoundResult.getStageResultList()) {
                        for (ElementalBondsBlock elementalBondsBlock : elementalBondsOperateStageResult.getEliminateBlockList()) {
                            for (ElementalBondsBlockEffect elementalBondsBlockEffect : elementalBondsBlock.getElementalBondsBlockEffectList()) {
                                if (elementalBondsBlockEffect.getEffectType() == ElementalBondsBlockEffectType.WU_CAI_BIN_FEN) {
                                    return true;
                                }
                            }
                        }
                    }
                }
            }
            return false;
        }
    }, // 加分最小值|加分最大值|0|0
    YAN_HUO_KUANG_HUAN(13, "烟火狂欢") {
        @Override
        public void init(ElementalBondsSceneConfig elementalBondsSceneConfig,
                         ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                         Random random) {
            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int initNum = paramList.get(0);

            // 拿格子
            List<ElementalBondsBlock> randomElementalBondsBlockList = new ArrayList<>();
            List<List<ElementalBondsBlock>> blockList = elementalBondsGameData.getBlockList();
            for (List<ElementalBondsBlock> elementalBondsBlockList : blockList) {
                for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlockList) {
                    if (elementalBondsBlock.getColor() != ElementalBondsColorType.RED.getType()
                            && elementalBondsBlock.getColor() != ElementalBondsColorType.BLUE.getType()
                            && elementalBondsBlock.getElementalBondsBlockType().getBigType() == ElementalBondsBlockBigType.NORMAL) {
                        randomElementalBondsBlockList.add(elementalBondsBlock);
                    }
                }
            }

            // 随机替换
            Collections.shuffle(randomElementalBondsBlockList, random);
            for (int i = 0; i < initNum && i < randomElementalBondsBlockList.size(); i++) {
                ElementalBondsBlock elementalBondsBlock = randomElementalBondsBlockList.get(i);
                elementalBondsBlock.setElementalBondsBlockType(ElementalBondsBlockType.YAN_HUO_KUANG_HUAN);
                elementalBondsBlock.setElementalBondsDirectionType(ElementalBondsDirectionType.getRandomType(random));
            }
        }

        @Override
        public void replaceDropBlock(ElementalBondsSceneConfig elementalBondsSceneConfig,
                                     ElementalBondsGameData elementalBondsGameData, List<ElementalBondsBlock> elementalBondsBlockList,
                                     Random random) {
            List<Integer> paramList = elementalBondsSceneConfig.getParamList();
            int boardMaxNum = paramList.get(0);
            int turnMaxNum = paramList.get(1);
            int ratio = paramList.get(2);

            // 回合数量
            int scene13Count = elementalBondsGameData.getScene13Count();
            if (scene13Count >= turnMaxNum) {
                return;
            }

            // 已有数量
            int haveNum = 0;
            for (List<ElementalBondsBlock> elementalBondsBlocks : elementalBondsGameData.getBlockList()) {
                for (ElementalBondsBlock elementalBondsBlock : elementalBondsBlocks) {
                    if (elementalBondsBlock != null) {
                        if (elementalBondsBlock.getElementalBondsBlockType() == ElementalBondsBlockType.YAN_HUO_KUANG_HUAN) {
                            haveNum++;
                        }
                    }
                }
            }
            if (haveNum >= boardMaxNum) {
                return;
            }

            // 随机替换
            List<ElementalBondsBlock> randomElementalBondsBlockList = new ArrayList<>();
            Collections.shuffle(randomElementalBondsBlockList);
            int limitNum = Math.min(boardMaxNum - haveNum, turnMaxNum - scene13Count);
            int realNum = 0;
            for (ElementalBondsBlock elementalBondsBlock : randomElementalBondsBlockList) {
                if (realNum >= limitNum) {
                    break;
                }
                if (random.nextInt(1000) < ratio) {
                    elementalBondsBlock.setElementalBondsBlockType(ElementalBondsBlockType.YAN_HUO_KUANG_HUAN);
                    elementalBondsBlock.setElementalBondsDirectionType(ElementalBondsDirectionType.getRandomType(random));
                    realNum++;
                }
            }

            // 修改数据
            elementalBondsGameData.setScene13Count(scene13Count);
        }
    }, // 稳定数量|掉落数量上限|替换概率千分比|0
    ;

    private final int type;
    private final String desc;

    ElementalBondsSceneType(int type, String desc) {
        this.type = type;
        this.desc = desc;
    }

    public static ElementalBondsSceneType forType(int type) {
        return Arrays.stream(ElementalBondsSceneType.values())
                .filter(elementalBondsSceneType -> elementalBondsSceneType.getType() == type)
                .findFirst()
                .orElse(EMPTY);
    }

    public static boolean containType(int type) {
        return Arrays.stream(ElementalBondsSceneType.values())
                .anyMatch(elementalBondsSceneType -> elementalBondsSceneType.getType() == type);
    }

    public int getType() {
        return type;
    }

    public String getDesc() {
        return desc;
    }

    public void refresh(ElementalBondsSceneConfig elementalBondsSceneConfig,
                        ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                        Random random) {
    }

    public void init(ElementalBondsSceneConfig elementalBondsSceneConfig,
                     ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                     Random random) {
        refresh(elementalBondsSceneConfig, elementalBondsGameData, elementalBondsOperateResult, random);
    }

    public void operateEnd(ElementalBondsSceneConfig elementalBondsSceneConfig,
                           ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateResult elementalBondsOperateResult,
                           Random random, boolean checkCanChange) {
    }

    public void afterSameColorEliminate(ElementalBondsSceneConfig elementalBondsSceneConfig, ElementalBondsGameData elementalBondsGameData, ElementalBondsOperateStageResult elementalBondsOperateStageResult,
                                        Set<ElementalBondsBlock> elementalBondsBlockSet, ElementalBondsOperateType elementalBondsOperateType) {
    }

    public void replaceDropBlock(ElementalBondsSceneConfig elementalBondsSceneConfig,
                                 ElementalBondsGameData elementalBondsGameData, List<ElementalBondsBlock> elementalBondsBlockList,
                                 Random random) {
    }

    public void eliminateEnd(ElementalBondsSceneConfig elementalBondsSceneConfig,
                             ElementalBondsGameData elementalBondsGameData, ElementalBondsPlayerData elementalBondsPlayerData,
                             ElementalBondsOperateResult elementalBondsOperateResult,
                             Random random, int roomRound, int turnPlayer) {

    }

}
